using System.Collections.Generic;

namespace NDomain.Reflection
{
    public abstract class BaseClassProcessor : IClassProcessor
    {
        protected delegate void DelayedProcessing();

        private List<DelayedProcessing> delayed;

        public void InitProcessing(IDomainInfo domainInfo)
        {
            delayed = new List<DelayedProcessing>();
        }

        public abstract void Process(IClassInfoProvider clazz, IDomainInfo domainInfo);

        public void FinalizeProcessing(IDomainInfo domainInfo)
        {
            foreach (DelayedProcessing processing in delayed)
            {
                processing.Invoke();
            }
        }

        protected void DelayProcessing(DelayedProcessing processing)
        {
            delayed.Add(processing);
        }

        protected static IDictionary<string, IAttributeInfoProvider> AttributesAsDictionary(
            IList<IAttributeInfoProvider> attributes)
        {
            Dictionary<string, IAttributeInfoProvider> dictionary = new Dictionary<string, IAttributeInfoProvider>();
            foreach (IAttributeInfoProvider attribute in attributes)
            {
                dictionary.Add(attribute.GetName(), attribute);
            }
            return dictionary;
        }
    }
}